<%--
Created by IntelliJ IDEA.
User: 沐白
Date: 2020/8/15
Time: 10:47
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>商品订单</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/bootstrap.min.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/toastr/toastr.min.css"/>
    <script src="${pageContext.request.contextPath}/static/js/jquery-2.1.0.js" type="text/javascript"
            charset="utf-8"></script>
    <script src="${pageContext.request.contextPath}/static/js/bootstrap.min.js" type="text/javascript"
            charset="utf-8"></script>
    <script src="${pageContext.request.contextPath}/static/toastr/toastr.min.js" type="text/javascript"
            charset="utf-8"></script>
    <script src="${pageContext.request.contextPath}/static/js/Myjs.js" type="text/javascript" charset="utf-8"></script>
</head>

<body>
<div class="form-group" style="margin-top: 10px">
    <div class="form-inline">
        <div class="form-group">
            <label>订单编号</label>
            <input type="text" class="form-control" id="orderId" placeholder="订单编号"/>
        </div>
        <div class="form-group">
            <label>会员卡号</label>
            <input type="text" class="form-control" id="cardId" placeholder="会员卡号"/>
        </div>
        <input type="button" class="btn btn-primary" id="btn" value="搜索订单"/>
    </div>
</div>
<div class="form-group">
    <table class="table table-bordered table-striped table-hover text-center">
        <tr class="info">
            <td>订单编号</td>
            <td>会员卡号</td>
            <td>会员等级</td>
            <td>应付金额</td>
            <td>实付金额</td>
            <td>商品积分</td>
            <td>备注</td>
            <td>创建时间</td>
            <td>操作</td>
        </tr>
        <tbody id="tb"></tbody>
    </table>
</div>
<%--下边的文字下拉菜单还有按钮 --%>
<div class="form-inline">
    <label>显示第 <span id="rowstart"></span> 到第 <span id="rowend"></span> 条记录,总共<span id="rowcount"></span>条记录
        每页显示
        <select class="form-control" id="pageSize">
            <option value="5">5</option>
            <option value="10">10</option>
            <option value="20">20</option>
            <option value="50">50</option>
            <option value="100">100</option>
        </select>
        条记录</label>
    <label class="btn-group pull-right">
        <a href="javascript:search(pageBean.pageNo-1)" class="btn btn-default"><</a>
        <div id="btns" class="btn-group"></div>
        <a href="javascript:search(pageBean.pageNo+1)" class="btn btn-default">></a>
    </label>
</div>
<div class="modal fade" id="xfdd">
    <div class="modal-dialog modal-lg modal-content">
        <div class="modal-header">
            <button class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title">订单修改</h4>
        </div>
        <div class="modal-body">
            <form id="xiugai">
                <div class="form-group">
                    <div class="row">
                        <div class="form-group col-sm-4">
                            <div class="input-group">
                                <label class="input-group-addon">订单编号</label>
                                <input type="text" class="form-control" name="orderId" placeholder="订单编号"
                                       disabled="disabled"/>
                                <span class="glyphicon form-control-feedback"></span>
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                            <div class="input-group">
                                <label class="input-group-addon">会员卡号</label>
                                <input type="text" class="form-control" name="cardId" placeholder="会员卡号"
                                       disabled="disabled"/>
                                <span class="glyphicon form-control-feedback"></span>
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                            <div class="input-group">
                                <label class="input-group-addon">会员等级</label>
                                <input type="text" class="form-control" name="name" placeholder="会员等级"
                                       disabled="disabled"/>
                                <span class="glyphicon form-control-feedback"></span>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group col-sm-4">
                            <div class="input-group">
                                <label class="input-group-addon">应付金额</label>
                                <input type="text" class="form-control" name="price" placeholder="应付金额"
                                       disabled="disabled"/>
                                <span class="glyphicon form-control-feedback"></span>
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                            <div class="input-group">
                                <label class="input-group-addon">实付金额</label>
                                <input type="text" class="form-control" name="pay" placeholder="实付金额"
                                       disabled="disabled"/>
                                <span class="glyphicon form-control-feedback"></span>
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                            <div class="input-group">
                                <label class="input-group-addon">会员积分</label>
                                <input type="text" class="form-control" name="credit" placeholder="会员积分"
                                       disabled="disabled"/>
                                <span class="glyphicon form-control-feedback"></span>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group col-sm-12">
                            <div class="input-group">
                                <label class="input-group-addon">创建时间</label>
                                <input type="text" class="form-control" id="cjshijian" name="name" placeholder="创建时间"
                                       disabled="disabled"/>
                                <span class="glyphicon form-control-feedback"></span>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group col-sm-12">
                            <div class="input-group">
                                <label class="input-group-addon">备注</label>
                                <textarea class="form-control" name="momo" placeholder="备注"></textarea>
                                <span class="glyphicon form-control-feedback"></span>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
        <div class="modal-footer">
            <input type="button" class="btn btn-default" data-dismiss="modal" value="关闭"/>
            <input type="button" class="btn btn-primary" onclick="queren()" value="确认"/>
        </div>
    </div>
</div>
<div class="modal fade" id="shdd">
    <div class="modal-dialog modal-lg modal-content">
        <div class="modal-header">
            <button class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title">订单修改</h4>
        </div>
        <div class="modal-body">
            <form id="shenhe">
                <div class="form-group">
                    <table class="table table-bordered table-striped table-hover text-center">
                        <tr class="info">
                            <td>商品编号</td>
                            <td>商品名称</td>
                            <td>商品数量</td>
                            <td>商品单价</td>
                            <td>商品积分</td>
                        </tr>
                        <tbody id="ddxq"></tbody>
                        <tr>
                            <td>应付金额</td>
                            <td class="ddxqzxx"></td>
                            <td>实付金额</td>
                            <td colspan="2" class="ddxqzxx"></td>
                        </tr>
                    </table>
                </div>
            </form>
        </div>
        <div class="modal-footer">
            <input type="button" class="btn btn-default" data-dismiss="modal" value="关闭"/>
            <input type="button" class="btn btn-primary" data-dismiss="modal" value="确认"/>
        </div>
    </div>
</div>

</body>
<script type="text/javascript">
    let pageBean = new Object();
    pageBean.pageNo = 1;
    pageBean.pageSize = 5;
    pageBean.factor = [];

    function search(num) {
        //判断上一页有没有
        if (num > 0) {
            pageBean.pageNo = num;
        } else {
            pageBean.pageNo = 1;
            num = 1;
        }
        //判断下一页有没有
        if (num <= pageBean.totalPage) {
            pageBean.pageNo = num;
        } else {
            if (pageBean.totalPage != 0) {
                pageBean.pageNo = pageBean.totalPage;
            } else {
                pageBean.pageNo = 1;
            }
        }
        //判断职位名称填写没有
        if ($('#orderId').val() != "") {
            if ($('#orderId').val().indexOf("'") >= 0) {
                pageBean.factor.push(" 1=0 ");
            } else {
                pageBean.factor.push(" orderId like '%" + $('#orderId').val() + "%' ");
            }
        }
        if ($('#cardId').val() != "") {
            if ($('#cardId').val().indexOf("'") >= 0) {
                pageBean.factor.push(" 1=0 ");
            } else {
                pageBean.factor.push(" cardId like '%" + $('#cardId').val() + "%' ");
            }
        }
        pageBean.data = "";
        show();
    }

    //界面开始时候的显示数据
    function show() {
        $.ajax({
            url: "${pageContext.request.contextPath}/orderController/show",
            data: pageBean,
            success: function (date) {
                pageBean = date;
                pageBean.factor = [];
                $('#rowcount').html(pageBean.rowCount);
                $('#rowstart').html(pageBean.rowCount == 0 ? 0 : pageBean.startIndex + 1);
                let con = pageBean.rowCount == 0 ? 0 :
                    pageBean.pageNo == pageBean.totalPage ?
                        pageBean.rowCount % pageBean.pageSize == 0 ?
                            pageBean.pageSize : pageBean.rowCount % pageBean.pageSize
                        : pageBean.pageSize;
                $('#rowend').html(pageBean.startIndex + con);
                let btns = "";
                for (let i = 0; i < pageBean.totalPage; i++) {
                    if (pageBean.pageNo == i + 1) {
                        btns += "<a href='javascript:search(" + (i + 1) + ");' class='btn btn-primary'>" + (i + 1) + "</a>";
                    } else {
                        btns += "<a href='javascript:search(" + (i + 1) + ");' class='btn btn-default'>" + (i + 1) + "</a>";
                    }
                }
                $('#btns').html(btns);
                //表格显示
                let tr = "";
                let orders = pageBean.data;
                if (orders != null) {
                    for (let i = 0; i < orders.length; i++) {
                        let cardId = "游客";
                        if (orders[i]['cardId'] != null) {
                            cardId = orders[i]['cardId'];
                        }
                        let cardtypeName = "游客";
                        if (orders[i]['cardtype'] != null) {
                            cardtypeName = orders[i]['cardtype']['name'];
                        }
                        let momo = "";
                        if (orders[i]['momo'] != null) {
                            momo = orders[i]['momo'];
                        }
                        tr += "<tr>\n" +
                            "<td>" + orders[i]['orderId'] + "</td>\n" +
                            "<td>" + cardId + "</td>\n" +
                            "<td>" + cardtypeName + "</td>\n" +
                            "<td>" + parseFloat(orders[i]['price']).toFixed(2) + "</td>\n" +
                            "<td>" + parseFloat(orders[i]['pay']).toFixed(2) + "</td>\n" +
                            "<td>" + orders[i]['credit'] + "</td>\n" +
                            "<td>" + momo + "</td>\n" +
                            "<td>" + orders[i]['createdTime'] + "</td>\n" +
                            "<td>\n" +
                            "<input type=\"button\" class=\"btn btn-primary btn-sm\" onclick='shenhe()' value=\"详情\" />\n" +
                            "</td>\n" +
                            "</tr>";
                    }
                }
                $('#tb').html(tr);
            },
            dataType: "json"
        });

    }

    //审核
    function shenhe() {
        let status = event.target.parentNode.parentNode.getElementsByTagName("td")[6].innerHTML;
        let orderId = event.target.parentNode.parentNode.firstElementChild.innerHTML;
        $.ajax({
            url: "/orderController/shenHe",
            type: "post",
            data: {orderId: orderId},
            success: function (data) {
                let tr = "";
                if (data['infos'] != null) {
                    for (let i = 0; i < data['infos'].length; i++) {
                        let name = "";
                        if (data['infos'][i]['goods'] != null) {
                            name = data['infos'][i]['goods']['name'];
                        }
                        tr += "<tr>" +
                            "<td>" + data['infos'][i]['goodsId'] + "</td>" +
                            "<td>" + name + "</td>" +
                            "<td>" + data['infos'][i]['goodsNumber'] + "</td>" +
                            "<td>" + data['infos'][i]['goodsPrice'] + "</td>" +
                            "<td>" + data['infos'][i]['goodsCredit'] + "</td>" +
                            "</tr>";
                    }
                }
                $('#ddxq').html(tr);
                $('#ddxq').append("<input type='hidden' value='" + data['order']['orderId'] + "' />");
                let ddxqxx = $('.ddxqzxx');
                ddxqxx[0].innerHTML = data['order']['price'];
                ddxqxx[1].innerHTML = data['order']['pay'];
                $('#shdd').modal('show');
            },
            dataType: "json"
        })
    }

    // function ddshqueren() {
    //     console.log($('#ddxq :hidden'));
    //     $.ajax({
    //         url: "/orderController/shenHeqr",
    //         type: "post",
    //         data: {orderId: $('#ddxq :hidden').val()},
    //         success:function (data) {
    //             if(data==1){
    //                 toastr.success("审核成功");
    //             }else{
    //                 toastr.error("审核失败");
    //             }
    //             $('#shdd').modal('hide');
    //             search(pageBean.pageNo);
    //         },
    //         dataType:"json"
    //     })
    // }

    /*//修改
    function xiugai() {
        let orderId = event.target.parentNode.parentNode.firstElementChild.innerHTML;
        $.ajax({
            url: "/orderController/findByOrderId",
            type: "post",
            data: {orderId: orderId},
            success: function (data) {
                let cardId = "";
                if (data['cardId'] != null) {
                    cardId = data['cardId'];
                }
                let cardtypeName = "";
                if (data['cardtype'] != null) {
                    cardtypeName = data['cardtype']['name'];
                }
                let momo = "";
                if (data['momo'] != null) {
                    momo=data['momo'];
                }
                let inps=$('#xiugai input');
                inps[0].value=data['orderId'];
                inps[1].value=cardId;
                inps[2].value=cardtypeName;
                inps[3].value=data['price'];
                inps[4].value=data['pay'];
                inps[5].value=data['credit'];
                inps[6].value=data['createdTime'];
                $('#xiugai select').val(data['status']);
                $('#xiugai textarea').val(momo);
                $('#xfdd').modal('show');
            },
            dataType: "json"
        })
    }

    //修改确认
    function queren(){
        $("#xfdd").modal('hide');
    }*/

    $(function () {
        search(1);
        $('#btn').click(function () {
            search(1);
        });
        $('#pageSize').on('change', function () {
            pageBean.pageSize = parseInt($('#pageSize').val());
            search(1);
        });
    });
</script>
</html>